<template>
  <div>
    <div v-for="(conversationInfo,index) in conversationList" :key="conversationInfo.id"
         @click="changeConversationDetail(index)" style="display: flex">
      <div>
        <!--        <img class="avatar" :src="require('../../assets/Images/'+conversationInfo.imageurl)" alt="">-->
        <Avatar :img-url="getImageurl(conversationInfo.id)" class-type="avatar"></Avatar>
      </div>
      <div>
        <div class="title">
          {{ conversationInfo.title }}
        </div>
        <div class="lastMessage">
          {{ lastMessage(index) }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Avatar from "../contact/Avatar";
export default {
  name: "ConversationList",
  data() {
    return {
      conversationList: this.$store.state.conversationList
    }
  },
  components:{
    Avatar
  },
  computed: {
    getImageurl() {
      return (senderId) => {
        console.log(senderId)
        console.log()
        return this.$store.getters.getImageUrl(senderId)
      }
    },
  },
  methods: {
    changeConversationDetail(index) {
      this.$store.dispatch('changeCurrentConversationIndex', index)
    },
    lastMessage(id) {
      return this.$store.getters.lastMessage(id)
    }
  },
}
</script>

<style scoped>
.title {
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "黑体", Arial, sans-serif;
  font-size: 13px;
  margin-left: 10px;
  font-weight: bold;
}

.lastMessage {
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑 Light", Arial, sans-serif;
  font-size: 12px;
  margin-left: 10px;
  color: gray;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  width: 170px;
}

.avatar {
  background-color: gray;
  width: 40px;
  height: 40px;
  margin: 0 0 0 10px;
  border-radius: 10px;
}
</style>
